package org.icosagon.core.magic;

import java.util.HashMap;
import org.icosagon.core.InvalidNumberException;

/**
 *
 * @author Daniel Owens
 */
public class DefaultSpellChart {
    private HashMap<Integer, Integer> slots = new HashMap<Integer, Integer>();

    public void addNumberOfSpellSlots(int level, int value) {
        if(level < 0 || value < 0)
            throw new InvalidNumberException("Parameters can not be negative.");
        Integer key = new Integer(level);
        value = this.slots.get(key).intValue() + value;
        this.slots.put(key, value);
        key = null; //cleanup
    }

    public void decreaseNumberOfSpellSlots(int level, int value) {
        if(level < 0 || value < 0)
            throw new InvalidNumberException("Parameters can not be negative.");
        Integer key = new Integer(level);
        value = this.slots.get(key).intValue() - value;
        this.slots.put(key, value);
        key = null; //cleanup
    }

    public void incrementNumberOfSpellSlots(int level) {
        this.addNumberOfSpellSlots(level, 1);
    }

    public int getNumberOfSpellSlots(int level) {
        if(level < 0)
            throw new InvalidNumberException("Parameter can not be negative.");
        return this.slots.get(new Integer(level)).intValue();
    }

    public int getNumberOfSpellSlots() {
        int total = 0;
        for(Integer i : this.slots.values()) {
            total += i.intValue();
        }
        return total;
    }
}